List Generator

The List generator generates parameters based on an arbitrary list of key/value pairs (as long as the values are string values). In this example, we’re targeting a local cluster named engineering-dev:

  1. apiVersion: argoproj.io/v1alpha1
  2. kind: ApplicationSet
  3. metadata:
  4. name: guestbook
  5. namespace: argocd
  6. spec:
  7. generators:
  8. - list:
  9. elements:
  10. - cluster: engineering-dev
  11. url: https://kubernetes.default.svc
  12. # - cluster: engineering-prod
  13. # url: https://kubernetes.default.svc
  14. # foo: bar
  15. template:
  16. metadata:
  17. name: '{{cluster}}-guestbook'
  18. spec:
  19. project: "my-project"
  20. source:
  21. repoURL: https://github.com/argoproj/argo-cd.git
  22. targetRevision: HEAD
  23. path: applicationset/examples/list-generator/guestbook/{{cluster}}
  24. destination:
  25. server: '{{url}}'
  26. namespace: guestbook

(The full example can be found here.)

In this example, the List generator passes the url and cluster fields as parameters into the template. If we wanted to add a second environment, we could uncomment the second element and the ApplicationSet controller would automatically target it with the defined application.

With the ApplicationSet v0.1.0 release, one could only specify url and cluster element fields (plus arbitrary values). As of ApplicationSet v0.2.0, any key/value element pair is supported (which is also fully backwards compatible with the v0.1.0 form):

  1. spec:
  2. generators:
  3. - list:
  4. elements:
  5. # v0.1.0 form - requires cluster/url keys:
  6. - cluster: engineering-dev
  7. url: https://kubernetes.default.svc
  8. values:
  9. additional: value
  10. # v0.2.0+ form - does not require cluster/URL keys
  11. # (but they are still supported).
  12. - staging: "true"
  13. gitRepo: https://kubernetes.default.svc
  14. # (...)

Clusters must be predefined in Argo CD

These clusters must already be defined within Argo CD, in order to generate applications for these values. The ApplicationSet controller does not create clusters within Argo CD (for instance, it does not have the credentials to do so).